using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace DFSGenerator
{
    public class DFA : IDFA //todo write fabric
    {
        public DFA(int pointNumber, List<string> alphabet, Random random)
        {
            this.pointNumber = pointNumber;
            this.alphabet = alphabet;

            this.func = new Dictionary<int, Dictionary<string, int>>();
            for (int startPoint = 1; startPoint <= pointNumber; startPoint++)
            {
                func.Add(startPoint, new Dictionary<string, int>());
                foreach (var symbol in alphabet)
                {
                    var endPoint = random.Next(1, pointNumber + 1);
                    func[startPoint].Add(symbol, endPoint);
                }
            } 
        }

        public int pointNumber { get; private set; }
        public List<string> alphabet { get; private set; }
        public Dictionary<int, Dictionary<string, int>> func { get; private set; }
        public string ToHumanReadableString()
        {
            StringBuilder returned = new StringBuilder();
            returned.Append(pointNumber).AppendLine();
            foreach (var pair in func)
            {
                returned.Append(pair.Key).Append(": ");
                foreach (var line in pair.Value)
                {
                    returned.Append(String.Format("{1}-{0} ", line.Key, line.Value));
                }
                returned.AppendLine();
            }
            return returned.ToString();
        }
    }
}